#ifndef _MOVEWINDOW_H
#define _MOVEWINDOW_h

#include <deque>

using namespace std;

class MoveWindow
{
public:
    int L, R, arrLen;
    int *arr;
    deque<int> qMax;

    MoveWindow(int* arr, int arrLen)
    {
        L = -1;
        R = 0;
        this->arr = arr;
        this->arrLen = arrLen;
    }

    void RightForward() // 右边界前进，则将值尾插入
    {
        if(R == arrLen)
            return;
        //修改&&后判断，即可改变滑动窗口记录的最值
        while(!qMax.empty() && arr[qMax.back()] <= arr[R])
            qMax.pop_back();
        qMax.push_back(R++);
    }

    void LeftForward() //左边界前进，头部等于移动经过下标时弹出
    {
        if(L >= R - 1)
            return;
        if(qMax.front() == ++L)
            qMax.pop_front();
    }

    int GetMax()
    {
        return qMax.empty() ? -114514 : arr[qMax.front()];
    }
};

#endif